<?php
abstract class Person{
	protected $peId;
	protected $viewerPeId;
    	protected $nickName;
	protected $name;
	protected $firstName;
	protected $eMail;
	protected $twitterName;
	protected $facebookName;
	protected $generalPrivacy;
	protected $contactPrivacy;
	//protected $services;	//should not be necessary in the abstract class
	//protected $found;	//should not be necessary in the abstract class
	//Contains the <div> witha all data
	protected $dataDiv;
 
	protected $db;

	function __construct($peId, $viewerPeId){
		$this->db		= new mysqli('localhost', 'root', 'gibbiX12345', 'msghub');

		$this->peId		= $peId;
		$this->viewerPeId	= $viewerPeId;

		//add functions here
		$this->fetchPrivacy();
		$this->fetchPersonData();
	}

	function fetchPrivacy(){
		$query			= "SELECT * FROM `Privacy` WHERE PeId = ".$this->peId;
		$result			= $this->db->query($query);
		$row			= $result->fetch_assoc();

		$this->generalPrivacy	= $row['OpenPrivacySetting'];
		$this->contactPrivacy	= $row['ContactsPrivacySetting'];
	}

	function fetchPersonData(){
	    	$nameQuery		= "SELECT * FROM `Person` WHERE PeId = ".$this->peId;
	    	$mailQuery		= "SELECT * FROM `Email` WHERE PeId = ".$this->peId;
		$twitterQuery		= "SELECT * FROM `Twitter` WHERE PeId = ".$this->peId;

		$nameResult		= $this->db->query($nameQuery);
		$mailResult		= $this->db->query($mailQuery);
		$twitterResult		= $this->db->query($twitterQuery);

		$nameRow		= $nameResult->fetch_assoc();
		$mailRow		= $mailResult->fetch_assoc();
		$twitterRow		= $twitterResult->fetch_assoc();

		$this->nickName		= $nameRow['Username'];
		$this->name		= $nameRow['Name'];
		$this->firstName	= $nameRow['Firstname'];
		$this->eMail		= $mailRow['EmailAdress'];
		$this->twitterName	= $twitterRow['TwitterName'];
	}

	// Getter and Setter
	public function getPeId(){
		return $this->peId;
	}
	public function getName(){
		return $this->name;
	}
	public function getFirstName(){
		return $this->firstName;
	}
	public function getEMail(){
		return $this->eMail;
	}
	public function getTwitterName(){
		return $this->twitterName;
	}
	public function getGeneralPrivacy(){
		return $this->generalPrivacy;
	}
	public function getContactPrivacy(){
		return $this->contactPrivacy;
	}
	public function getDataDiv(){
		return $this->dataDiv;
	}
	public function setViewerPeId($viewer){
	    $this->viewerPeId = $viewer;
	}
	public function getViewerPeId(){
	    return $this->viewerPeId;
	}
}
?>
